package com.mytest.thread;

import com.mytest.entity.Student;

import java.text.SimpleDateFormat;
import java.util.Date;

public class MyThread extends Thread {

    private int i;
    private Student student;

    public int getI() {
        return i;
    }

    public void setI(int i) {
        this.i = i;
    }

    public MyThread(int i) {
        this.i = i;
    }

    public MyThread() {
    }

    public Student getStudent() {
        return student;
    }

    public void setStudent(Student student) {
        this.student = student;
    }

    @Override
    public void run() {

        int score = student.getScore();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd  HH:mm:ss");
        System.out.println("Thread Start:"+sdf.format(new Date()));
        for (int j=0;j<10;j++){
            score++;
            i++;
        }
        System.out.println("Thread End:"+sdf.format(new Date()));
        student.setScore(score);
        System.out.println(student.getScore());
    }

    public static void main(String[] args) throws InterruptedException {

        //线程死亡后不能重新运行java.lang.IllegalThreadStateException
        /*Thread thread = new MyThread();
        thread.start();
        thread.join();
        if (3>1){
            thread.start();
        }*/

        //实例变量int类型默认为0
        /*Thread thread = new MyThread();
        thread.start();*/

        //方法传参相当于=引用变量，=对基本数据类型是值传递，对引用数据类型是引用数据类型
        /*int num = 1;
        MyThread thread = new MyThread(num);
        thread.start();
        thread.join();
        System.out.println(num);*/

        //引用变量传参的用法，涉及到int类型时
        /*MyThread thread = new MyThread();
        Student student = new Student();
        student.setScore(5);
        thread.setStudent(student);
        thread.start();
        thread.join();
        System.out.println("score:"+student.getScore());*/


        //thread id name toString()的区别
        /*Thread thread1 = new Thread();
        System.out.println(thread1.getId());
        System.out.println(thread1.getName());
        System.out.println(thread1.toString());*/

        MyThread myThread = new MyThread();
        myThread.setStudent(new Student());

        myThread.start();
        myThread.join(60000);
        System.out.println("hello");
    }
}
